﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SWCInvoice.Enums;
using SWCInvoice.Model;

namespace SWCInvoice.Returntyps {
    
    /// <summary>
    /// Result of the SetPageIdentifier method
    /// </summary>
    public class SetPageIdentifierInfo : BaseInfo {

        #region Constanten

        /// Base object resource typ
        private const string RESOURCE_STRING = "SetPageIdentifier";

        #endregion

        #region Fields

        /// <summary>
        /// The primary identifier key
        /// </summary>
        private string _identifierKey; 
        /// <summary>
        /// The regex search pattern
        /// </summary>
        private string _pattern;
        /// <summary>
        /// Is inheritance is on
        /// </summary>
        private bool _inheritance;
        /// <summary>
        /// The document count
        /// </summary>
        private int _documentCount;
        /// <summary>
        /// The page count
        /// </summary>
        private int _pageCount;
        /// <summary>
        /// The identifier count
        /// </summary>
        private int _identifierCount;

        #endregion

        #region Properties

        /// <summary>
        /// Base object resource typ
        /// </summary>        
        public override string ResourceString {
            get { return RESOURCE_STRING; }
        }

        /// <summary>
        /// The primary identifier key
        /// </summary>        
        public string IdentifierKey {
            get { return _identifierKey; }
            set { _identifierKey = value; }
        }       

        /// <summary>
        /// The regex search pattern
        /// </summary>
        public string Pattern {
            get { return _pattern; }
            set { _pattern = value; }
        }        

        /// <summary>
        /// Is inheritance is on
        /// </summary>
        public bool Inheritance {
            get { return _inheritance; }
            set { _inheritance = value; }
        }
        
        /// <summary>
        /// The document count
        /// </summary>
        public int DocumentCount {
            get { return _documentCount; }
            set { _documentCount = value; }
        }
        
        /// <summary>
        /// The page count
        /// </summary>
        public int PageCount {
            get { return _pageCount; }
            set { _pageCount = value; }
        }

        /// <summary>
        /// The identifier count
        /// </summary>
        public int IdentifierCount {
            get { return _identifierCount; }
            set { _identifierCount = value; }
        }

        #endregion

        #region Construcctor

        public SetPageIdentifierInfo(string identifierKey, string pattern, bool inheritance) {
            _identifierKey = identifierKey;
            _pattern = pattern;
            _inheritance = inheritance;
            
            
            MessageTyp = MessageTyp.None;
            _documentCount = 0;
            _pageCount = 0;
            _identifierCount = 0;
        }

        #endregion

        #region Methods

        public override MessageTyp SetMessageTypByObjectContent() {            
            if (IdentifierCount < PageCount)
                MessageTyp = MessageTyp.Warning;
            else
                MessageTyp = MessageTyp.Information;
            
            return MessageTyp;
        }

        public override Message EnrichMessageWithParameters(Message message) {            
            if (MessageTyp == MessageTyp.Warning || MessageTyp == MessageTyp.Information)
                message.Description = string.Format(message.Description, IdentifierCount, PageCount);

            if (MessageTyp == MessageTyp.Error)
                message.Description = string.Format(message.Description, ExceptionList[0].Message);
            
            return message;
        }

        #endregion
    }
}
